#include <55header.h>

void copy_file(const char *src, const char *dest){
    // 打开src和dest
    FILE *srcp = fopen(src, "r");
    //if(srcp == NULL){
    //    perror("foepn");
    //    exit(1);
    //}
    //
    ERROR_CHECK(srcp, NULL, "fopen src");
    FILE *destp = fopen(dest, "w");
    if(destp == NULL){
        fclose(srcp);
        perror("fopen dest");
        exit(1);
    }

    // 循环读循环写
    char buf[1024 * 1024 * 7] = { 0 };
    int count;
    while((count = fread(buf, 1, sizeof(buf), srcp)) > 0){
        fwrite(buf, 1, count, destp);
    }
    fclose(srcp);
    fclose(destp);

}
long long current_time_millis()
{
    struct timespec ts;
    clock_gettime(CLOCK_REALTIME, &ts); // 获取当前时间
    return (long long)ts.tv_sec * 1000LL + ts.tv_nsec / 1000000; // 转换为毫秒
}
// Usage: ./copy src dest
int main(int argc, char *argv[])
{
    // 命令行参数个数的校验
    //if(argc != 3){
    //    fprintf(stderr, "argc error!\n");
    //    exit(1);
    //}
    ARGS_CHECK(argc, 3);
    long long t1 = current_time_millis();
    copy_file(argv[1], argv[2]);
    long long t2 = current_time_millis();
    printf("dif = %lld\n", (t2 - t1));
    return 0;
}

